package http

import (
	"context"
	"gitee.com/byx_darwin/micro-extend/pkg/config/hertz_conf"
	"gitee.com/byx_darwin/uptrace-opentelemetry/otelplay"
	serverconfig "github.com/cloudwego/hertz/pkg/common/config"
	"github.com/cloudwego/hertz/pkg/common/hlog"
	hertztracing "github.com/hertz-contrib/obs-opentelemetry/tracing"
)

func NewServerTracer(server hertz_conf.Server, service hertz_conf.Service,
	log hlog.CtxLogger) (serverconfig.Option, *hertztracing.Config) {
	if server.Jaeger.Enable {
		ctx := context.Background()
		shutdown := otelplay.ConfigureOpentelemetry(ctx, &otelplay.Config{
			ServiceDSN:     server.Jaeger.Endpoint,
			ServiceName:    service.Name,
			ServiceVersion: service.Version,
			Environment:    service.Env,
		})
		defer shutdown()
		log.CtxDebugf(ctx,
			"服务端配置链路已配置成功 ServiceName：%v，Endpoint:%v",
			service.Name, server.Jaeger.Endpoint)
	}
	return hertztracing.NewServerTracer()
}
